package com.foreveross.bsl.mam.app.application.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.inject.Named;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;

import com.foreveross.bsl.common.utils.bean.BeanHelper;
import com.foreveross.bsl.common.utils.enums.OperatEnum;
import com.foreveross.bsl.mam.app.application.AppSecretApplication;
import com.foreveross.bsl.mam.app.application.vo.AppSecretVo;
import com.foreveross.bsl.mam.model.app.domain.AppSecret;

/**
 * @author tanzhixiong
 * @2013-6-22 @上午10:54:20
 */
@SuppressWarnings("unused")
@Named("appSecretApplication")
public class AppSecretApplicationImpl implements AppSecretApplication {

	@Override
	public AppSecretVo saveEntity(AppSecretVo entity) {
		AppSecret appSecret = new AppSecret();
		BeanHelper.copyProperties(appSecret, entity);
		appSecret.save();
		BeanHelper.copyProperties(entity, appSecret);
		return entity;
	}

	@Override
	public AppSecretVo updateEntity(AppSecretVo entity) {
		AppSecret appSecret = new AppSecret();
		BeanHelper.copyProperties(appSecret, entity);
		AppSecret secret = (AppSecret) appSecret.save();
		BeanHelper.copyProperties(entity, secret);
		return entity;
	}

	@Override
	public void deleteEntity(String id) {
		AppSecret appSecret = new AppSecret();
		appSecret.delete(id);
	}

	@Override
	public AppSecretVo getEntity(String id) {
		AppSecret appSecret = new AppSecret();
		appSecret = (AppSecret) appSecret.findOne(id);
		AppSecretVo appSecretVo = new AppSecretVo();
		BeanHelper.copyProperties(appSecretVo, appSecret);
		return appSecretVo;
	}

	@SuppressWarnings("unchecked")
	@Override
	public AppSecretVo findByAppId(String appid, String platform) {
		// TODO Auto-generated method stub
		AppSecret appSecret = new AppSecret();
		List<AppSecret> list = appSecret.findListByProperty(new String[] {
				"appid", "platform" }, new OperatEnum[] { OperatEnum.EQ,
				OperatEnum.EQ }, new String[] { appid, platform });
		List<AppSecretVo> result = new ArrayList<AppSecretVo>();
		if (list != null && list.size() > 0) {
			AppSecretVo secretVo = new AppSecretVo();
			BeanHelper.copyProperties(secretVo, list.get(0));
			return secretVo;
		}
		return null;
	}

}
